package com.gb.demand.common.api;

import com.gb.demand.common.entity.Goodscart;
import com.gb.demand.common.entity.Orderform;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResultMap {


    /**
     * 获取token时的返回结果
     *
     * @param accessToken
     * @param returnMsg
     * @param isSuccess
     * @return
     */
    public static Map generateResultMap(String accessToken, String returnMsg, boolean isSuccess) {
        Map map = new HashMap();
        map.put("accessToken", accessToken);
        map.put("returnMsg", returnMsg);
        map.put("isSuccess", isSuccess);
        return map;
    }

    /**
     * 公采云失败返回结果
     *
     * @param desc
     * @return
     */
    public static Map gcyFaileResultMap(String desc) {
        Map map = new HashMap();
        map.put("success", false);
        map.put("desc", desc);
        return map;
    }

    /**
     * 公采云token过期失败返回结果
     *
     * @return
     */
    public static Map gcyFaileTokenResultMap() {
        Map map = new HashMap();
        map.put("success", false);
        map.put("desc", "token_expired");
        return map;
    }

    /**
     * 公采云成功返回结果
     *
     * @param accessToken
     * @return
     */
    public static Map gcySucceedResultMap(String accessToken,String expiresAt) {
        Map map = new HashMap();
        map.put("success", true);
        map.put("access_token", accessToken);
        map.put("expires_at", expiresAt);
        return map;
    }

    /**
     * 公采云带参数返回的格式 第一个参数可以自定义
     *
     * @param firstKey
     * @param firstValue
     * @return
     */
    public static Map gcySuccessResultMapwithKey(String firstKey, Object firstValue) {
        Map map = new HashMap();
        map.put(firstKey, firstValue);
        map.put("success", true);
        return map;
    }

    /**
     * 公采云带参数返回的格式 第一个参数可以自定义
     *
     * @param firstKey
     * @param firstValue
     * @return
     */
    public static Map gcySuccessResultMapwithKeyandDesc(String firstKey, Object firstValue,String desc) {
        Map map = new HashMap();
        map.put(firstKey, firstValue);
        map.put("success", true);
        map.put("desc", desc);
        return map;
    }


    /**
     * 三个参数的返回格式 第一个参数可以自定义
     *
     * @param firstKey
     * @param firstValue
     * @param returnMsg
     * @param isSuccess
     * @return
     */
    public static Map generateResultMapwithKey(String firstKey, Object firstValue, String returnMsg, boolean isSuccess) {
        Map map = new HashMap();
        map.put(firstKey, firstValue);
        map.put("returnMsg", returnMsg);
        map.put("isSuccess", isSuccess);
        return map;
    }

    public static Map generateResultMapwithKey(String returnMsg, boolean isSuccess) {
        Map map = new HashMap();
        map.put("returnMsg", returnMsg);
        map.put("isSuccess", isSuccess);
        return map;
    }

    /**
     * 四个参数的返回格式 第一个参数可以自定义
     *
     * @param firstKey
     * @param firstValue
     * @param returnMsg
     * @param isSuccess
     * @return
     */
    public static Map generateResultMapwithDoubleKey(String firstKey, Object firstValue, String secondKey, Object secondValue, String returnMsg, boolean isSuccess) {
        Map map = new HashMap();
        map.put(firstKey, firstValue);
        map.put(secondKey, secondValue);
        map.put("returnMsg", returnMsg);
        map.put("isSuccess", isSuccess);
        return map;
    }

    public static Map generateResultMapforCreateOrderForm(Orderform of, List<Goodscart> goodsCartList, String errorCode, String returnMsg, boolean isSuccess) {
        String orderId = "";
        List<Map> skuvaluelist = new ArrayList<>();
        BigDecimal amount = new BigDecimal(0);
        BigDecimal freight = new BigDecimal(0);

        System.out.println("of1111:" + of);
        if (of != null && goodsCartList != null && goodsCartList.size() > 0) {
            orderId = of.getOrderId();
            for (Goodscart gc : goodsCartList) {
                Map skuvaluemap = new HashMap();
                skuvaluemap.put("skuId", gc.getGoodsId().toString());
                skuvaluemap.put("num", gc.getCount());
                skuvaluelist.add(skuvaluemap);
            }
            amount = of.getTotalPrice();
            freight = of.getShipPrice();
        }

        Map resultMap = new HashMap();
        resultMap.put("orderId", orderId);
        resultMap.put("sku", skuvaluelist);
        resultMap.put("arriveData", "");//预计到达时间
        resultMap.put("amount", amount);//
        resultMap.put("freight", freight);
        resultMap.put("errorCode", errorCode);
        resultMap.put("returnMsg", returnMsg);
        resultMap.put("isSuccess", isSuccess);
        return resultMap;
    }


}
